//
//  ClassroomInquireVC.m
//  SchoolTask
//
//  Created by tusm on 16/8/26.
//  Copyright © 2016年 sm. All rights reserved.
//

#import "ClassroomInquireVC.h"
#import "ClassroomInquire.h"
#import "Layout.h"
#import "CollectionViewCell.h"

#define kScreenW [UIScreen mainScreen].bounds.size.width
#define kScreenH [UIScreen mainScreen].bounds.size.height


@interface ClassroomInquireVC ()<UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>

@property (nonatomic,retain) UICollectionView *collection;
@property (nonatomic,retain) NSMutableArray   *timeMArray;
@end

@implementation ClassroomInquireVC

- (NSMutableArray *)timeMArray {
    
    if (!_timeMArray) {
        
        _timeMArray = [NSMutableArray arrayWithObjects:@"教室",@"08:00",@"10:00",@"14:00",@"16:00",@"19:00",@"21:00",@"jiio",@"dll",@"iso",nil];
    }
    return _timeMArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    ClassroomInquire *classroom = [[ClassroomInquire alloc]init];
    [self.view addSubview:classroom];
    
    //创建一个layout布局类
    Layout *layout = [[Layout alloc]init];
    //    // 设置item尺寸
    layout.itemSize = CGSizeMake(kScreenW/20, 20);
    //    // 设置item之间的间隔
    layout.minimumInteritemSpacing = 0;
    //    // 设置行之间间隔
    layout.minimumLineSpacing = 0;
    
    //    // 设置组的内边距
    layout.sectionInset = UIEdgeInsetsMake(-2, -2, -2, -2);

    //设置布局方向为垂直流布局
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    //创建collectionView 通过一个布局策略layout来创建
    _collection = [[UICollectionView alloc]initWithFrame:self.view.frame collectionViewLayout:layout];
    //代理设置
    _collection.delegate=self;
    _collection.dataSource=self;
    //注册item类型 这里使用系统的类型
    [_collection registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"cell"];
    _collection.frame = CGRectMake(0, 200, kScreenW , kScreenH-250);
    
    _collection.backgroundColor = [UIColor colorWithRed:220/255.0 green:240/255.0 blue:250/255.0 alpha:1];

    [self.view addSubview:_collection];
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    
    return kScreenW/20;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return kScreenW/20;
}


- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    
    CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];

    cell.backgroundColor   = [UIColor whiteColor];
    cell.layer.borderColor = [[UIColor colorWithRed:230/255.0 green:240/255.0 blue:250/255.0 alpha:1] CGColor];


    if (indexPath.section == 0) {
        
        //假数据赋值
//        cell.titleLb.text = self.timeMArray[indexPath.row];
        
    }
    
    cell.layer.borderWidth = 2;
    [cell setNeedsDisplay];

    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didEndDisplayingCell:(UICollectionViewCell *)cell forItemAtIndexPath:(NSIndexPath *)indexPath {
    
    CollectionViewCell *collection = (CollectionViewCell *)cell;
    collection.titleLb.text = nil;
    collection.backgroundColor = [UIColor whiteColor];
}

- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
    
    return 1;
}

//-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
//{
//    return UIEdgeInsetsMake(0, 0, 0, 0);
//}

//两个cell之间的间距（同一行的cell的间距）
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
  
    return 0;
}


//-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
//    
//    CGSize size = CGSizeMake(kScreenW/,50);
//    return size;
//}
////这个是两行cell之间的间距（上下行cell的间距）
//- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
//    
//    return 0;
//}
//
//
//
//
////两个cell之间的间距（同一行的cell的间距）
//- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
//    
//    return 0;
//}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
